package com.gewu.pm.ui.adapter.terminal;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.PromotionBean;

/**
 * 终端促销活动适配器
 */
public final class TerminalPromotionAdapter extends AppAdapter<PromotionBean> {

    public TerminalPromotionAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder();
    }

    private final class ItemViewHolder extends AppAdapter<PromotionBean>.ViewHolder {

        private final TextView mTitleView;
        private final TextView mStatusView;
        private final TextView mNameView;
        private final TextView mDateView;
        private final TextView mMainProductScopeView;
        private final TextView mGiftScopeView;
        private final TextView mActivityTypeView;
        private final TextView mCouponTypeView;
        private final TextView mIssueTimeView;

        private ItemViewHolder() {
            super(R.layout.terminal_promotion_item);
            mTitleView = findViewById(R.id.tv_title);
            mStatusView = findViewById(R.id.tv_status);
            mNameView = findViewById(R.id.tv_name);
            mDateView = findViewById(R.id.tv_date);
            mMainProductScopeView = findViewById(R.id.tv_main_product_scope);
            mGiftScopeView = findViewById(R.id.tv_gift_scope);
            mActivityTypeView = findViewById(R.id.tv_activity_type);
            mCouponTypeView = findViewById(R.id.tv_coupon_type);
            mIssueTimeView = findViewById(R.id.tv_issue_time);
        }

        @Override
        public void onBindView(int position) {
            PromotionBean bean = getItem(position);
            String title = bean.getName();
            int type = bean.getType(); //1.买赠活动  2.满减活动 3.优惠券活动

            // TODO: 根据实际数据设置
            mTitleView.setText(title);

            // 示例数据
            if (type == 1) {//1.买赠活动
                mStatusView.setText("进行中");
                mStatusView.setTextColor(getResources().getColor(R.color.red_app));
                mNameView.setText("促销活动名称: 购买祖名老豆腐4000g3盒, 赠送祖名浓浆豆腐400g1盒");
                mDateView.setText("活动日期: 2025-08-11~2025-08-18");
                mMainProductScopeView.setText("主品范围: 指定商品(买赠)");
                mGiftScopeView.setText("赠品范围: 指定商品");
                //mGiftScopeView.setVisibility(android.view.View.VISIBLE);
                mActivityTypeView.setText("活动类型: 区域活动");
                //mCouponTypeView.setVisibility(android.view.View.GONE);
                //mIssueTimeView.setVisibility(android.view.View.GONE);
            } else if (type == 2) {//2.满减活动
                mStatusView.setText("未开始");
                mStatusView.setTextColor(getResources().getColor(R.color.green_01));
                mNameView.setText("促销活动名称: 满20减2元");
                mDateView.setText("活动日期: 2025-08-11~2025-08-18");
                mMainProductScopeView.setText("主品范围: 指定商品(买赠)");
                //mGiftScopeView.setVisibility(android.view.View.GONE);
                mActivityTypeView.setText("活动类型: 公司活动");
                //mCouponTypeView.setVisibility(android.view.View.GONE);
                //mIssueTimeView.setVisibility(android.view.View.GONE);
            } else if (type == 3) {//3.优惠券活动
                mStatusView.setText("已结束");
                mStatusView.setTextColor(getResources().getColor(R.color.cb9));
                mNameView.setText("促销活动名称: 5元优惠券");
                mDateView.setText("活动日期: 2025-08-11~2025-08-18");
                //mMainProductScopeView.setVisibility(android.view.View.GONE);
                //mGiftScopeView.setVisibility(android.view.View.GONE);
                mCouponTypeView.setText("优惠券类型: 有门槛/无门槛");
                //mCouponTypeView.setVisibility(android.view.View.VISIBLE);
                mIssueTimeView.setText("发放时间: 2025/08/11 16:40:32");
                //mIssueTimeView.setVisibility(android.view.View.VISIBLE);
                mActivityTypeView.setText("活动类型: 公司活动");
            }
        }
    }
}

